/*
* @(#)NotificationWayFactory.java
*
* Copyright (c) 2003 DCIVision Ltd
* All rights reserved.
*
* This software is the confidential and proprietary information of DCIVision
* Ltd ("Confidential Information").  You shall not disclose such Confidential
* Information and shall use it only in accordance with the terms of the license
* agreement you entered into with DCIVision Ltd.
*/
package com.dcivision.framework.notification;

import java.io.UnsupportedEncodingException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.dcivision.framework.SystemParameterConstant;
import com.dcivision.framework.SystemParameterFactory;
import com.dcivision.framework.Utility;
import com.dcivision.framework.bean.GenericAddress;

/**
 * <p>Class Name:       NotificationWayFactory.java    </p>
 * <p>Description:      This class monitors the system notification by: </p>
 *                      - email
 *
 * @author           Zoe Shum
 * @company          DCIVision Limited
 * @creation date    02/07/2003
 * @version          $Revision: 1.11.2.1 $
 */
 
public class NotificationWayFactory {

  public static final String REVISION = "$Revision: 1.11.2.1 $";
  
  private static final Log log = LogFactory.getLog(NotificationWayFactory.class);

  /**
   *  Method getNotificationInstance() - get the way of notification for EIP
   *
   *  @param      notification           The class name of email notification instance
   *  @return     NotificationWay        The abstract object that can be implemented by the notify way
   *  @throws     No exception throws
   */
  public static NotificationWay getNotificationInstance(String notification) {
    NotificationWay noti = null;
    if (NotificationWay.EMAIL_NOTIFICATION_INSTANCE.equals(notification)) {
      if (Utility.isEmpty(SystemParameterFactory.getSystemParameter(SystemParameterConstant.DOMINO_HOST))) {
	      noti = new EmailNotification();
	    } else {
	      noti = new LotusDominoNotification();
	    }
    }
    return noti;
  }

  /**
   *  main - demo of distribute email
   *
   *  static main
   *
   *  @param      args[]
   *  @return     No return value
   *  @throws     UnsupportedEncodingException     Throws UnsupportedEncodingException if email encoding fail
   *  @throws     Exception                        Throws Exception if email send fail
   */
  public static void main(String[] args) {
    try {
      StringBuffer content = new StringBuffer();
      content.append("Dear Sir Mandam,\n\n");
      content.append("This is the testing email for DCIVision Mail.\n");
      EmailDeliveryMessage msg = new EmailDeliveryMessage();
      msg.setSender(new GenericAddress("zoe.shum@dcivision.com", "Sys Admin", "UTF-8"));
      msg.addToRecipient(new GenericAddress("zoe.shum@dcivision.com", "Zoe Shum", "UTF-8"));
      msg.setSubject("Testing Email Subject");
      msg.setMailContent(content.toString());
      NotificationWay emailNotification = NotificationWayFactory.getNotificationInstance(NotificationWay.EMAIL_NOTIFICATION_INSTANCE);
      emailNotification.addDeliveryMessage(msg);
      emailNotification.send();
    } catch (UnsupportedEncodingException unsee) {
      log.error(unsee, unsee);
    } catch (Exception e){
      log.error(e, e);
    }
  }
}